package com.dingteam.question.common.validation.module;

import com.dingteam.model.Result;
import com.dingteam.question.common.dto.QuestionPaperVerifyDTO;
import com.dingteam.question.common.dto.QuestionResultVerifyDTO;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 问答形式的组件
 * @author Jamin
 * @date 2019/08/14
 */
public abstract class AbstractModuleTextValidator implements ModuleValidator {

	protected static final int MAX_VALUE = 1000;

	protected Result<String> validCreateCommon(QuestionPaperVerifyDTO.QuestionItemDTO itemDTO) {
		if (Objects.isNull(itemDTO.getRequired())) {
			return Result.error("{validation.item.required.null.message}", EMPTY);
		}
		return Result.ok().build();
	}

	protected Result<String> validSubmitCommon(QuestionResultVerifyDTO.ItemResultDTO item) {
		if (Objects.equals(true, item.getQuestionItem().getRequired())) {
			if (StringUtils.isBlank(item.getContent())) {
				return Result.error("{validation.required.content.blank.message}", EMPTY);
			}
		}
		return Result.ok().build();
	}
}
